﻿@using System.Data
@{
    ViewBag.Title = "个人信息编辑";
    Layout = "~/Areas/Mall/Views/Shared/MallLayout1.cshtml";
   
}
<div class="title_t">
    个人信息
</div>
<script src="/Scripts/ajaxfileupload.js"></script>
<div class="add_sh" style="height: 500px;">
    <p></p>
    <div>
        <img src="@ViewData["img"]" class="imgheader" />
        <a class="sc_img" onclick="checkfile()">上传</a>
        <input id="fileToUpload" style="display: none; cursor: pointer;" type="file" onchange="upload()" name="upfile">
    </div>
    <p>性别：</p>
    <div id="sexlist">
        <input type="radio" value="1" class="user_sez" name="sex"  />男&nbsp;&nbsp;
        <input type="radio" value="0" class="user_sez" name="sex"/>女
    </div>
    <p>昵称：</p>
    <div>
        <input type="text" id="nicheng" value="@ViewData["ncname"]" style="width: 80%;">
    </div>
    <p>姓名：</p>
    <div>
        <input type="text" id="name" value="@ViewData["name"]" style="width: 50%;">
    </div>
    <p>联系电话：</p>
    <div>
        <input type="text" id="tell" value="@ViewData["tell"]" style="width: 70%;">
    </div>
</div>
<div class="usersave">保存</div>

<div style="width: 100%;height: 100px;float: left;margin-top: 20px;"></div>

<script>
    $(function() {

        var sex = "@ViewData["sex"]";
        if (sex == 1) {
            $(".user_sez:eq(0)").attr("checked", "checked");
        } else {
            $(".user_sez:eq(1)").attr("checked", "checked");
        }
    });

    function checkfile() {
        $('#fileToUpload').click();
    }
    function upload() {
        var val = $("#fileToUpload").val();
        if (val == "") {
            alert("请上传文件");
            return false;
        }
        var suffix = val.split('.');
        var arr = new Array("png", "jpg", "gif");
        if (arr.indexOf(suffix[suffix.length - 1]) < 0) {
            alert("上传格式有误！");
        } else {
            $.ajaxFileUpload({
                url: '@Url.Action("UploadImg")',
                secureuri: false,
                fileElementId: 'fileToUpload',
                dataType: 'json',
                success: function(data, status) {
                    var str = "";
                    if (data.status == 1) {
                        $(".imgheader").attr("src", data.path);
                        return false;

                    } else {

                    }

                }
            });
        }
    }

    $(".usersave").click(function() {
        var nicheng = $("#nicheng").val();
        if (nicheng.replace(/\s/g, "").length == 0) {
            alert("请输入昵称！");
            return false;
        } else {
            if (nicheng.length > 20) {
                alert("昵称只能小于20个字！");
                return false;
            }
        }
        var name = $("#name").val();
        if (name.replace(/\s/g, "").length == 0) {
            alert("请输入姓名！");
            return false;
        } else {
            if (name.length > 20) {
                alert("姓名只能小于10个字！");
                return false;
            }
        }
     
        var tell = $("#tell").val();
        var reg1 = /^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$/;
        if (!reg1.test(tell)) {
            alert("电话号码输入有误！");
            return false;
        }
        var sex = $('#sexlist input[name="sex"]:checked ').val();
        $.post("@Url.Action("EditUserInfo")", { img: $(".imgheader").attr("src"), name: name,  tell: tell, sex: sex, ncname: nicheng }, function (row) {
            if (row > 0) {
                alert("修改成功！");
            }
        });
    });

</script>